package com.university.report.model.entity;

import com.alibaba.excel.annotation.ExcelProperty;
import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.ToString;
import org.springframework.security.core.GrantedAuthority;
import org.springframework.security.core.userdetails.UserDetails;

import java.util.ArrayList;
import java.util.Collection;
import java.util.List;

/**
 * @ClassName health_report
 * @Author Jinondo
 * @Date 2021/6/16 17:27
 */
@Data
@ToString
@EqualsAndHashCode(callSuper = false)
@TableName("t_user")
public class UserAccount implements UserDetails {

    @ExcelProperty(value = "用户id")
    @TableId(value = "user_id", type = IdType.AUTO)
    private Integer userId;

    @ExcelProperty(value = "用户名")
    private String username;

    @ExcelProperty(value = "密码")
    private String password;

    /**
     * 学号
     */
    @ExcelProperty(value = "学号")
//    @TableField(exist = false)
    private String stuNumber;

    @ExcelProperty(value = "角色")
    @TableField(exist = false)
    private String roleName;

    @TableField(exist = false)
    //我需要一个身份，就算role表里面的 roleName，分管理员和普通用户，请把这个值也传进token里面，我前端需要根据token进行相应的跳转页面
    String identity;
    /**
     * 用户所有权限
     */
    @TableField(exist = false)
    private List<GrantedAuthority> authorities = new ArrayList<GrantedAuthority>();


    @Override
    public Collection<? extends GrantedAuthority> getAuthorities() {
        return authorities;
    }

    @Override
    public boolean isAccountNonExpired() {
        return true;
    }

    @Override
    public boolean isAccountNonLocked() {
        return true;
    }

    @Override
    public boolean isCredentialsNonExpired() {
        return true;
    }

    @Override
    public boolean isEnabled() {
        return true;
    }

}
